import axios from "axios"
import {RootAction} from '../index'
import {Channel} from '../../stroe/index'
// 频道列表的类型
export type channelAction={
    type:"GET_CHANNEL",
    data:Channel[]
} | {
    type:'CHANGE_ID',
    id:number
}
// 获取频道列表的action 异步dispatch的返回值是RootAction
export const getChannel=():RootAction=>{
   return async (dispatch)=>{
        const res = await axios.get('http://geek.itheima.net/v1_0/channels')
        console.log(res,'频道列表是');
        // 保存数据到redux
        dispatch({
            type:"GET_CHANNEL",
            data:res.data.data.channels
        })
    }
}
export const updateID=(id:number):RootAction=>{
    return (dispatch)=>{
         // 保存数据到redux
         dispatch({
             type:"CHANGE_ID",
             id
         })
     }
 }